//
//  AdviceViewController.m
//  沙哈拉FM
//
//  Created by dllo on 15/11/12.
//  Copyright © 2015年 S1mpl3. All rights reserved.
//

#import "AdviceViewController.h"
#import "FitHeader.h"
#import "BaseLabel.h"
#import "BaseButton.h"
#import "Model.h"
//#import "SKPSMTPMessage.h"
//#import "NSData+Base64Additions.h"

@interface AdviceViewController ()
@property(nonatomic, retain)UITextView *textView;
@property(nonatomic, retain)BaseButton *button;
@property(nonatomic, retain)BaseLabel *label;
@end

@implementation AdviceViewController

#pragma mark - 视图将要出现时
- (void)viewWillAppear:(BOOL)animated{
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-fanhui"] style:UIBarButtonItemStylePlain target:self action:@selector(goBack)];
    self.view.backgroundColor = [Model shareInstance].ViewColor;

}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"意见反馈";
    
}

- (void)loadView{
    [super loadView];
    
    self.label = [[BaseLabel alloc]initWithFrame:CGRectMake(10 * FITWidth, 20 * FITHeight, 200 * FITWidth, 20 * FITHeight)];
    _label.text = @"请输入您的反馈意见";
    [_label setFontSize:16];
    [self.view addSubview:_label];

    
    self.textView = [[UITextView alloc]initWithFrame:CGRectMake(_label.frame.origin.x, _label.frame.origin.y + _label.frame.size.height + 5 * FITHeight, 355 * FITWidth, 200 * FITHeight)];
    _textView.layer.borderColor = [UIColor blackColor].CGColor;
    _textView.layer.borderWidth = 1.0;
    [self.view addSubview:_textView];
    
    self.button = [BaseButton buttonWithType:UIButtonTypeSystem];
    _button.frame = CGRectMake(_textView.frame.origin.x, _textView.frame.origin.y + _textView.frame.size.height + 10 * FITWidth, _textView.frame.size.width, 35 * FITHeight);
    [_button setTitle:@"提交" forState:UIControlStateNormal];
    _button.layer.borderColor = [UIColor blackColor].CGColor;
    _button.layer.borderWidth = 1.0;
    [_button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_button addTarget:self action:@selector(submitAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_button];
}
/*
- (void)submitAction{
    UIAlertView *alterView1 = [[UIAlertView alloc]initWithTitle:@"警告" message:@"内容不能为空!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    if (_textView.text.length == 0) {
        [alterView1 show];
    }else
    {
        SKPSMTPMessage *myMessage = [[SKPSMTPMessage alloc]init];
        myMessage.fromEmail = @"rwzrwz449@163.com";
        myMessage.toEmail = @"alizhen821@163.com";
        myMessage.relayHost = @"smtp.163.com";//发件服务器
        myMessage.requiresAuth = YES;
        if (myMessage.requiresAuth) {
            myMessage.login = @"rwzrwz449@163.com";
            myMessage.pass = @"rwzrwz449@";
        }
        myMessage.wantsSecure = YES;
        myMessage.subject = @"意见反馈";
        myMessage.delegate = self;
        
        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain;charset = UTF-8", kSKPSMTPPartContentTypeKey, _textView.text, kSKPSMTPPartMessageKey, @"8bit", kSKPSMTPPartContentTransferEncodingKey, nil];
        myMessage.parts = [NSArray arrayWithObject:dic];
        [myMessage send];
        
        [_button setTitle:@"发送中..." forState:UIControlStateNormal];
    }
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0) {
        [self.navigationController popViewControllerAnimated:YES];
    }
}
- (void)messageSent:(SKPSMTPMessage *)message{
    NSLog(@"发送成功");
    UIAlertView *alterView2 = [[UIAlertView alloc]initWithTitle:@"提示" message:@"发送成功" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
    [alterView2 show];
}
- (void)messageFailed:(SKPSMTPMessage *)message error:(NSError *)error{
    NSLog(@"发送失败");
    UIAlertView *alterView1 = [[UIAlertView alloc]initWithTitle:@"警告" message:@"内容不能为空!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alterView1 show];
}
*/
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
